package com.hxx.day5;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.junit.Test;

import java.util.*;

public class TestDemo {

    //set去重
    public static void main(String[] args) {
        Random random = new Random();
        Set<Integer> set = new HashSet<>();
        for (int index = 0; index <10 ; index++) {
            int data = random.nextInt(10);
            set.add(data);
        }
        System.out.println(set);
        List list = new ArrayList<>();
        for (int index = 0; index < 9; index++) {
            if (!set.contains( index)){
                list.add(index);
            }
        }
        System.out.println(list);
    }

    //哈希码: 对象相同那么哈希码一定相同
    @Test
    public void test1(){
        String a = "hello";
        String b = "hello";
        System.out.println(a.hashCode());
        System.out.println(b.hashCode());
    }
    //哈希码: 哈希码相同,那么对象不一定相同
    @Test
    public void test2(){
        String a = "hello";
        String b = new String("hello");
        System.out.println(a.hashCode());
        System.out.println(b.hashCode());
    }

    @Test
    public void test3(){
        Person person = new Person();
        person.setId(1);
        person.setName("hxx");

        Person person1 = new Person();
        person1.setId(1);
        person1.setName("hxx1");

        //使用set集合
        Set set = new HashSet<>();
        set.add(person);
        set.add(person1);
        System.out.println(set);
        System.out.println(person.hashCode());
        System.out.println(person1.hashCode());
        System.out.println(person.equals(person1));
    }
}





























